package com.yhd.array;

/**
 * @author 二十
 * @since 2022/1/20 5:19 下午
 */
public class MyArray<E> extends AbstractArray<E> {

    private E[] data;

    private int size;

    public MyArray(int capacity) {
        data = (E[]) new Object[capacity];
    }

    public MyArray() {
        this(10);
    }

    @Override
    public int getSize() {
        return size;
    }

    @Override
    public int getCapacity() {
        return data.length;
    }

    @Override
    public boolean isEmpty() {
        return size == 0;
    }

    @Override
    public void addIndex(E e, int index) {
        if (index < 0 || index > size) {
            throw new IllegalArgumentException("illegal arg of index!");
        }
        if (size == data.length) {
            resize(size * 2);
        }
        for (int i = index + 1; i <= size; i++) {
            data[i] = data[i - 1];
        }
        data[index] = e;
    }

    @Override
    public void addFirst(E data) {
        addIndex(data,0);
    }

    @Override
    public void addLast(E data) {
        addIndex(data,size);
    }

    @Override
    public E deleteIndex(int index) {
        if (index < 0 || index >= size) {
            throw new IllegalArgumentException("illegal arg of index!");
        }
        E ret = data[index];
        for (int i = index+1; i < size; i++) {
            data[i-1]=data[i];
        }
        return ret;
    }

    @Override
    public E deleteFirst() {
        return deleteIndex(0);
    }

    @Override
    public E deleteLast() {
        return deleteIndex(size-1);
    }

    @Override
    public E get(int index) {
        return null;
    }

    @Override
    public void set(E data, int index) {

    }

    @Override
    public boolean contains(E data) {
        return false;
    }

    @Override
    public int find(E data) {
        return 0;
    }

    @Override
    public void clear() {

    }
}
